{
 "cells": [
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "`Date Mark 2023/5/5`\n",
    "\n",
    "### 图形学\n",
    "核心：去除画面中不需要的东西\n",
    "1. 模糊处理（常规模糊，高斯模糊）\n",
    "2. 灰度处理（`A`RGB）\n",
    "3. 二值处理\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "#普通模糊\n",
    "import cv2\n",
    "image = cv2.imread('qqicon.jfif')\n",
    "blur = cv2.blur(image,(30,60))\n",
    "cv2.imshow('image',image)\n",
    "cv2.imshow('blur',blur)\n",
    "cv2.waitKey()\n",
    "cv2.destroyAllWindows()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "#高斯模糊\n",
    "import cv2\n",
    "image = cv2.imread('qqicon.jfif')\n",
    "blur = cv2.GaussianBlur(image,(31,31),0)\n",
    "cv2.imshow('image',image)\n",
    "cv2.imshow('blur',blur)\n",
    "cv2.waitKey()\n",
    "cv2.destroyAllWindows()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "image = cv2.imread('qqicon.jfif')\n",
    "blur = cv2.GaussianBlur(image,(31,31),0) #模糊\n",
    "gray = cv2.cvtColor(image,6) # 转灰度\n",
    "_,binary = cv2.threshold(gray,120,255,8) # 转二值 # threshold -> 阈值（门槛）\n",
    "cv2.imshow('image',image)\n",
    "cv2.imshow('blur',blur)\n",
    "cv2.imshow('gray',gray)\n",
    "cv2.imshow('binary',binary)\n",
    "cv2.waitKey()\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "camera = cv2.VideoCapture(0)\n",
    "while True:\n",
    "    _,image = camera.read()\n",
    "    blur = cv2.GaussianBlur(image,(13,13),0) #模糊\n",
    "    gray = cv2.cvtColor(image,6) # 转灰度\n",
    "    _,binary = cv2.threshold(gray,120,255,8) # 转二值 # threshold -> 阈值（门槛）\n",
    "    cv2.imshow('image',image)\n",
    "    cv2.imshow('blur',blur)\n",
    "    cv2.imshow('gray',gray)\n",
    "    cv2.imshow('binary',binary)\n",
    "    if cv2.waitKey(1)>0:\n",
    "        break\n",
    "cv2.destroyAllWindows()\n",
    "camera.release()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
